﻿module game.sprite;

import gamelib.types;
import gamelib.graphics.renderer2d.renderer;
import gamelib.graphics.renderer2d.textureview;

import game.game;
import game.units;

struct Sprite
{
    private TextureView mTexture;

    this(TextureView tex) pure nothrow
    {
        mTexture = tex;
    }

    void draw(Renderer ren, in Point pt)
    {
        auto srcRect = mTexture.rect;
        Rect dstRect = {x:pt.x - mTexture.width / 2,
                        y:pt.y - mTexture.height / 2,
                        w:mTexture.width,
                        h:mTexture.height};
        ren.draw(mTexture.texture, &srcRect, &dstRect);
    }

    void draw(Renderer ren, in Point pt, in double dir)
    {
        auto srcRect = mTexture.rect;
        Rect dstRect = {x:pt.x - mTexture.width / 2,
                        y:pt.y - mTexture.height / 2,
                        w:mTexture.width,
                        h:mTexture.height};
        ren.draw(mTexture.texture, &srcRect, &dstRect, dir);
    }
}
